const app = getApp()
Page({
  data: {
    sqRea: '',
    topicId: '',
    topicName: '',
    teaId: ''
  },
  onLoad: function(options) {
    this.setData({
      topicId: options.topicId,
      topicName: options.topicName,
      teaId: options.teaId
    })
  },
  inpRes: function(e) {
    this.setData({
      sqRea: e.detail.value
    })
  },
  funApp: function() {
    const that = this
    if (that.data.sqRea == '') {
      wx.showToast({
        title: '申请理由不能为空！',
        icon: 'none',
        duration: 2000
      })
    } else {
      wx.cloud.callFunction({
        name: 'topicApply',
        data: {
          stuId: app.globalData.userId,
          stuName: app.globalData.userName,
          topicId: that.data.topicId,
          topicName: that.data.topicName,
          teaId: that.data.teaId,
          sqRea: that.data.sqRea
        }
      }).then(res => {
        if (res.result.result == 1) {
          wx.showToast({
            title: '选题申请发送成功！',
            icon: 'success',
            duration: 2000
          })
          setTimeout(function() {
            wx.navigateBack({
              delta: 1
            })
          }, 2500)
        }else{
          wx.showToast({
            title: '选题申请发送失败！',
            icon: 'none',
            duration: 2000
          })
        }
      })
    }
  }
})